#include "Control.h"


Control* Control::singleControl = NULL;


int main(int argc, char** argv)
{	
	Control* control = Control::getInstance();
	control->start(argc, argv);

	return 0;
}


void Control::start(int argc, char** argv)
{
	int cmdCount = 1;

	//einlesen bis wert von argc erreicht
	while (cmdCount < argc && cmdCount > 0)
	{
		switch (cmdCount)
		{
			case 1:
				if (strcmp(rand_cmd, (const char*)argv[cmdCount]) == 0)
				{
					rand_on = true;
					cmdCount++;
				}
				else
				if (strcmp(lrand_cmd, (const char*)argv[cmdCount]) == 0)
				{
					lrand48_on = true;
					cmdCount++;
				}
				else
				{
					std::cout << "Ungueltiger Eingabeparameter";
					cmdCount = -1;
				}
				break;

			case 2:
				numberOfprn = atoi(argv[cmdCount]);
				cmdCount++;
				break;

			case 3:
				outputPath = new std::string(argv[cmdCount]);
				cmdCount++;
				break;
		}
	}

	if (rand_on)
		use_rand();
	else
	if (lrand48_on)
		use_lrand48();

}


void Control::use_rand()
{
	int randomNumber;
	int bufferSize;
	int numberOfprn;
	int loopruns;
	char* outputPath;

	numberOfprn = getNumberOfprn();
	outputPath = getOutputPath();

	srand(time(NULL));


	bufferSize = (numberOfprn / 8) + (numberOfprn % 8); 
	buffer = new char[bufferSize];
	memset(buffer, 'A', bufferSize);

	loopruns = (numberOfprn / (8 * INT_SIZE)) + (numberOfprn % 8);

	for (int i = 0; i < loopruns; i++)
	{
		randomNumber = rand();
		for (int j = 0; j < INT_SIZE; j++)
		{
			buffer[i*INT_SIZE + j] = (char)randomNumber;
			randomNumber = randomNumber >> 8;
		}
	}
	ioUnit->writeToFile(outputPath, buffer, bufferSize);
}


void Control::use_lrand48()
{
	


}
